import router from './router'
import store from '@/store'

router.beforeEach((to, from, next) => {
	const {
		state: { isLogin },
		dispatch,
		commit
	} = store
	if (!isLogin) {
		const {
			query: { code, state, spmId, userAccount },
			path
		} = to
		if (code && state) {
			;(async () => {
				await dispatch('handleLoginStatus', { code, state, spmId, userAccount })
				commit('HANDLE_LOGIN_INFO', { code, state, spmId, userAccount })
				next(path)
			})()
		} else {
			// to.matched.some(record => record.meta?.requiresAuth) ? next('login') : next()
		}
	} else {
		next()
	}
	// next()
})

export default router
